home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15047 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: help with program
  5. Date: 16 Apr 1996 15:19 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <16APR199615190586@erich.triumf.ca>
  9. References: <4kkgde$t2m@news.duke.edu> <4kvl0e$g4c@hpbblb.bbn.hp.com>
  10. NNTP-Posting-Host: erich.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <4kvl0e$g4c@hpbblb.bbn.hp.com>, Matthias Dittrich <matti> writes...
  14. >kev@acpub.duke.edu (Kevin Daniels) wrote:
  15. >>
  16. >>Can anyone tell me why the following slice of code might be giving the 
  17. >>unwanted behavior shown below?
  18. ..snip...
  19. >>    printf("\n\nmove from row -> ");
  20. >>    scanf("%d",&curr_row);
  21. >>    printf("\n\nmove from col -> ");
  22. >>    scanf("%d",&curr_col);
  23. >>    printf("\n\nmove to row -> ");
  24. >>    scanf("%d",&dest_row);
  25. >>    printf("\n\nmove to col -> ");
  26. >>    scanf("%d",&dest_col); 
  27. >>    
  28. .. more snippage...
  29.  
  30. >The function scanf() requires a '\n' character to accept input. You have to
  31. >remove this character from the input stream. A call of fflush(stdin) before
  32. >each scanf() should work.
  33.  
  34. No. successive scanf()s will work OK - each one sees the '\n' left by the
  35. previous one as "whitespace" and eats it, before reading the new input.  The
  36. leftover '\n' is only a problem if you mix scanf() and getchar() or other 
  37. input functions.
  38.  
  39. The action of fflush() on input streams is undefined - on some systems it _may_
  40. clear the input buffer, but this is not required by the standard.
  41.  
  42.  
  43. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  44. Internet: bennett@triumf.ca         | of one another only when one can be
  45. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  46. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  47. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  48. or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
  49. or: http:://vancouver-webpages.com/peter/index.html
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.